/**
 * @author Cator Vee  hi@catorv.com
 */
export default function guid () {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    const rand = Math.random() * 16 | 0
    const value = c === 'x' ? rand : (rand & 0x3 | 0x8)
    return value.toString(16)
  })
}

let runtimeUniqueId = 1

export function ruid (element) {
  if (element) {
    return element.id || (element.id = ruid())
  } else {
    return '__id_' + runtimeUniqueId++
  }
}
